#!/usr/bin/perl -w

####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################

#===================================================================================================
# BigDaddy History Table Dump
# Dumps the History table into SQL dump files.
# Dups 17.04.2006
#===================================================================================================


BEGIN
{
	push(@INC,'/bigdaddy')
}


use strict;
use Config::IniFiles;
use BioMain qw(:allfunctions);
use Time::Local;

#my $cronID=169;\
#&cronstart($cronID);

my $dbConfigMain = "/bigdaddy/bigdaddy_dbconfig.ini";
my $dbConfigPHP = "/bigdaddy/bigdaddy_dbconfig_php.inc";

my $bdConfigMainMod = (stat $dbConfigMain)[9];
my $bdConfigPHPMod = (stat $dbConfigPHP)[9];

if (!defined($bdConfigPHPMod))
{
	$bdConfigPHPMod = 0;
}

#if the MainMod has been modified run
if ($bdConfigMainMod > $bdConfigPHPMod)
{
	my $cfgDBConfig= new Config::IniFiles( -file => $dbConfigMain );
	my @cfgSections = $cfgDBConfig->Sections;
	
	my $sPHPStr = "";
	
	for (my $i=0; $i<scalar(@cfgSections); $i++)
	{
		$sPHPStr .=
		"\n\n
		\$aDBInfo['".$cfgSections[$i]."']['pass']=\"".$cfgDBConfig->val($cfgSections[$i], 'pass')."\";
		\$aDBInfo['".$cfgSections[$i]."']['user']=\"".$cfgDBConfig->val($cfgSections[$i], 'user')."\";
		\$aDBInfo['".$cfgSections[$i]."']['database']=\"".$cfgDBConfig->val($cfgSections[$i], 'database')."\";
		\$aDBInfo['".$cfgSections[$i]."']['host']=\"".$cfgDBConfig->val($cfgSections[$i], 'host')."\";";
	}
	
	if ($sPHPStr ne '')
	{
		$sPHPStr = "<?php ".$sPHPStr." ?>";
		open(DBCONFIG_PHP, ">$dbConfigPHP") or die ("Can'd Open $dbConfigPHP: $!");
		print DBCONFIG_PHP $sPHPStr;
		close(DBCONFIG_PHP);
	}
}
	

#&cronend($cronID);
